package org.dh2580.delay.queue.bean.task;

import java.util.concurrent.Callable;

import org.dh2580.delay.queue.bean.AbstractMsgListener;
import org.dh2580.delay.queue.bean.model.Ack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Author: hao.deng
 * @Date: 2019/5/15-上午10:25
 */
public class ListenerTask implements Callable<Ack> {

    private static Logger LOG = LoggerFactory.getLogger(ListenerTask.class);

    private AbstractMsgListener listener;

    private String msg;

    public ListenerTask(AbstractMsgListener listener, String msg) {
        this.listener = listener;
        this.msg = msg;
    }

    @Override
    public Ack call() throws Exception {
        try {
            return listener.receiveMsg(msg);
        } catch (Exception ex) {
            LOG.error("receive msg error", ex);
            return Ack.FAIL_RETRY;
        }
    }
}
